//
//  BaseRequest.m
//  CoolTennisBall
//
//  Created by Coollang on 16/12/8.
//  Copyright © 2016年 CoolLang. All rights reserved.
//


#import "YFBaseRequest.h"

@interface YFBaseRequest ()
    
@end

@implementation YFBaseRequest

- (NSString *)requestUrl {
    return [YFBaseRequest requestString:self.apiType];
}

- (id)responseInfo{
    return [[self responseJSONObject] objectForKey:@"errDesc"];
}


- (id)requestArgument {
    return self.requestArgumentParma ? self.requestArgumentParma:nil;
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSInteger)cacheTimeInSeconds {
    return 8;
}

+ (instancetype)requestApiWithType:(RequestApiType)apiType andParam:(id)param {
    YFBaseRequest *api = [[self alloc] init];
    api.apiType = apiType;
    api.requestArgumentParma = param;
    return api;
}

- (NSError *)disposeRequestErrorWithRet:(NSString *)ret {
    return [YFNetError creatErrorWithRet:[YFNetError WebRespondTypeWithRet:ret]];
}

+ (NSString *)requestString:(RequestApiType)apiType {
    switch (apiType) {
//            七牛
        case kQINiuTopicUpImageGetTokenApi:
            return @"Tsns/getUpToken";
//            登录
        case kLoginRefreshApi:
            return @"/TLoginController/refreshLogin";
        case kLoginEmailSignUpApi:
            return @"/TLoginController/emailRegister";
        case kLoginEmailSignInApi:
            return @"/TLoginController/login";
        case kLoginPhoneSignInApi:
            return @"/TLoginController/phoneVerify";
        case kLoginByThirdPart:
            return @"/TLoginController/qqLoginCallBack";
        case kLoginFaceBookApi:
            return @"/TLoginController/facebookLogin";
        case kLoginForgotpasswordApi:
            return @"/AccountUserManagerController/getMyEmailCode";
        case kUserFeedbackApi:
            return @"/FeedbackController/feedBack";
//            个人模块
        case kUserSaveInfoApi:
            return @"/MemberController/updateMemberInfo";
        case kUserGetInfoApi:
            return @"/MemberController/getTennisUserInfo";
        case kUserUploadHeadImage:
            return @"/MemberController/uploadUserHeadIcon";
        case kUserGetYearHistoryDataApi:
            return @"/TennisSportController/getUserHistory";
        case kUserGetHomeDataApi:
            return @"/TennisSportController/getUserSnsInfo";
        case kUserGetEquipApi:
            return @"/TennisSportController/getEquipment";
        case KUserSaveEquipApi:
            return @"/TennisSportController/addEquipment";
        case kUserGetCareerDataListApi:
            return @"/TennisSportController/getCareer";
        case kUserDeleteCareerDataApi:
            return @"/TennisSportController/deleteCareer";
        case kUserAddCareerDataApi:
            return @"/TennisSportController/addCareer";
        case KUserUploadRactetImageApi:
            return @"/TennisSportController/uploadRacketIcon";
        case KUserUploadShoeImageApi:
            return @"/TennisSportController/uploadShoesIcon";
        case kUserGetShowMedalApi:
            return @"/TennisSportController/showMedals";
            
//            排行榜
        case kRankNewGetListAPi:
            return @"/TennisSportController/getRanking";
        case kRankNewAddLikeAPi:
            return @"/TennisSportController/addRankLike";
        case kRankNewCancelLikeAPi:
            return @"/TennisSportController/delRankLike";
        case kRankNewGetUserRankInfoAPi:
            return @"/TennisSportController/getMyRankInfo";
//            训练
        case kTrainGetHDTennisCoachListApi:
            return @"/TennisSportController/getHDVideoList";
        case kTrainGetOldTennisVideolistAPi:
            return @"/PracticeController/getTennisVideoList";
        case KTrainRealTimeGetSearveHistoryAPi:
            return @"/TennisSportController/getServePractice";
        case KTrainRealTimeGetForeBackHandHistoryAPi:
            return @"/TennisSportController/getPractice";
        case KTrainRealTimeSendSearveAPi:
            return @"/TennisSportController/addServePractice";
        case KTrainRealTimeSendForeBackHandAPi:
            return @"/TennisSportController/addPractice";
        case KTrainRealTimeDeleteHistortAPi:
            return @"/TennisSportController/deleteHistory";
//      运动统计
        case kStatisticGetUserUploadTimeApi:
            return @"/TennisSportController/getUserUploadTime";
        case kStatisticGetGetHomeSportDataApi:
            return @"/TennisSportController/getData";
        case kStatisticUploadHomeSportDataApi:
            return @"/TennisSportController/addTennisSportMainData";
        case kStatisticGetTargetApi:
            return @"/TargetParamController/getTennisTarget";
        case kStatisticSaveTargetApi:
            return @"/TargetParamController/addTennisTarget";
        case kStatisticGetRecordDeleteListApi:
            return @"/TennisSportController/getDeleteList";
        case kStatisticDeleteSportDataApi:
            return @"/TennisSportController/deleteDairyData";
        case kStatisticGetSportDetailReportAPi:
            return @"/TennisSportController/getAnalysisDetailReport";
//      设备
        case kSensorBindOemTypeAndMacAPi:
            return @"/HardwareController/bindUserOemType";
        case kSensorGetLastVersionAPi:
            return @"/VersionController/getLastVersion";
//      朋友圈
        case kPYQPostTopicAPi:
            return @"Tsns/post";
        case kPYQGetTopicListApi:
            return @"Tsns/getPostList";
        case kPYQTopicCommentAPi:
            return @"/Tsns/response";
        case kPYQTopicLikeApi:
            return @"Tsns/postLike";
        case kPYQTopicCancelLikeApi:
            return @"Tsns/delPostLike";
        case kPYQDeleteTopicApi:
            return @"Tsns/delPost";
        case kPYQDeleteTopicCommentApi:
            return @"Tsns/delPostResponse";
        default:
            break;
    }
    
}


@end

@implementation YFUrlArgumentsFilter {
    NSDictionary *_arguments;
}

+ (YFUrlArgumentsFilter *)filterWithArguments:(NSDictionary *)arguments {
    return [[YFUrlArgumentsFilter alloc] initWithArguments:arguments];
}
- (id)initWithArguments:(NSDictionary *)arguments {
    self = [super init];
    if (self) {
        _arguments = arguments;
    }
    return self;
}

- (NSString *)filterUrl:(NSString *)originUrl withRequest:(YFBaseRequest *)request {
    return [self urlStringWithOriginUrlString:originUrl withRequest:request appendParameters:_arguments];
}

- (NSString *)urlStringWithOriginUrlString:(NSString *)originUrlString withRequest:(YFBaseRequest *)request appendParameters:(NSDictionary *)parameters {
    
    NSString *paraUrlString = AFQueryStringFromParameters(parameters);
    if (!(paraUrlString.length > 0)) {
        return originUrlString;
    }
    return originUrlString;
}

@end

@implementation YFUrlCacheDirPathFilter

- (id)initWithUserId:(NSString *)userId {
    if (self = [super init]) {
        _userId = userId;
    }
    return self;
}

+ (YFUrlCacheDirPathFilter *)filterWithArguments:(NSString *)userId {
    return [[YFUrlCacheDirPathFilter alloc] initWithUserId:userId];
}

// 切换用户z则使用不同的缓存配置文件
- (NSString *)filterCacheDirPath:(NSString *)originPath withRequest:(YTKBaseRequest *)request {
    return originPath;
}

@end

